<template>
    <div>
        <Modal width="450"
               v-model="modal.addParofessionalFlag"
               @on-cancel="cancel"
               :loading="loading"
               title="添加专业">
            <div class="modalDiv"></div>
            <Form ref="parofessional" :model="major" :rules="ruleValidate" :label-width="130">
                <FormItem prop="name" label="专业名称">
                    <Input class="myform" v-model="major.name" clearable/>
                </FormItem>
                <FormItem prop="schoolMajorCode" label="专业代码">
                    <Input class="myform" v-model="major.schoolMajorCode" clearable/>
                </FormItem>
                <FormItem  label="学科类别">
                    <Input class="myform" v-model="major.typeCode" clearable/>
                </FormItem>
                <FormItem  label="专业代码（国标）">
                    <Input class="myform" v-model="major.majorCode" clearable/>
                </FormItem>
                <FormItem prop="collegeId" label="学院">
                    <Select v-model="major.collegeId" clearable class="myform">
                        <Option  v-for="item in modal.list" :value="item.collegeId" :key="item.collegeId">{{item.name}}</Option>
                    </Select>
                </FormItem>
            </Form>
            <Button type="primary" slot="footer" @click="ok"> 提交 </Button>
        </Modal>
    </div>
</template>

<script>
    import {AddProfessionalRuleValidate} from '../ruleValidate'
    export default {
        name: "addProfessional",
        props: {
            modal: {
                addParofessionalFlag: false,
                list:[]
            }
        },
        data(){
            return{
                loading:false,
                ruleValidate:AddProfessionalRuleValidate(),
                major:{},

            }
        },
        methods:{
            ok(){
                this.$refs["parofessional"].validate((valid) => {
                    if (valid) {
                        this.loading = true
                        this.major.createTime = new Date();
                        this.http.post("/parofessional/saveAddParofessional",this.qs.parse(this.major)).then(res=>{
                            if(res){
                                this.$Message.success('添加成功！');
                                this.modal.addParofessionalFlag = false;
                                this.$parent.getAllParofessional();
                            }else{
                                this.$Message.error('添加失败！！！');
                            }
                        })
                    } else {
                        this.$Message.error('不允许存在空值!');
                    }
                })
            },
            cancel() {
                this.cropperFlag = false
            },

        }
    }
</script>

<style scoped>
    .myform {
        width: 230px;
    }
</style>